﻿<?php
// ------------------------------------------------------------------
// NEEDED STUBS FOR THIS EXAMPLE
// ------------------------------------------------------------------


// this will include all needed files to be able to build a Request
include_once($CONF["STUBS_FOLDER"]."Map24Routing/Map24Routing.php5");


// ------------------------------------------------------------------
// NEEDED PARAMETERS FOR THIS REQUEST
// ------------------------------------------------------------------

// the start address
$sStreet	= 'Düsseldorfer Str.';
$sZip		= '63571';
$sCity		= 'Eschborn';
$sCountry	= 'DE';

// the destination address
$dStreet	= 'Domtr.';
$dZip		= '50668';
$dCity		= 'Köln';
$dCountry	= 'DE';

// the language for the route description
$descriptionLanguage = "EN";		//or try DE, NL ;o)


// ------------------------------------------------------------------
// BUILDING THE REQUEST
// ------------------------------------------------------------------


// definition of the request header with Map24ID and SessionID
$header = new RequestHeader();
$header->Map24ID  = $CONF['MAP24_ID'];
$header->ClientID = $CONF['SESSION_ID'];

// definition of the request body
$request = new CalculateRouteRequest();
$request->SearchText = $searchText;
$request->MaxNoOfAlternatives = $maxNoOfAlternatives;

// define the Start Address
$request->Start = new CoordinateAndAddress();
$request->Start->Address = new Address();
$request->Start->Address->Street = $sStreet;
$request->Start->Address->ZIP = $sZip;
$request->Start->Address->City = $sCity;
$request->Start->Address->Country = $sCountry;

// define the Destination Address
$request->Destination = new CoordinateAndAddress();
$request->Destination->Address = new Address();
$request->Destination->Address->Street = $dStreet;
$request->Destination->Address->ZIP = $dZip;
$request->Destination->Address->City = $dCity;
$request->Destination->Address->Country = $dCountry;

// define the Description Language
$request->DescriptionLanguage = $descriptionLanguage;


// ------------------------------------------------------------------
// EXECUTE THE REQUEST
// ------------------------------------------------------------------


// in this object the SoapClient will be initiated and executed
$routing = new Map24Routing($CONF['MAPTP_SYSTEM'],$CONF['MAP24_ID'],$CONF['SESSION_ID']);
$response = $routing->calculateRoute($header,$request);


// ------------------------------------------------------------------
// OUTPUT THE RESULT
// ------------------------------------------------------------------


if( isset($response->Route) )
{
	foreach ($response->Route->Segments as $result)
	{
		$counter++;

		$resultString .= "<div style='border:1px solid black;margin:2px 0px;padding:5px;'>".$counter.". ";
		foreach ( $result->Descriptions as $description )
		{
			$resultString .= $description->Text."<br /><br />";
		}
		$resultString .= "</div>";
	}

	$RouteID=$response->Route->RouteID;
	// save the RouteID in a cookie (needed to show the route later)
	$t=date("U")+3600;
	SetCookie("RouteID",$RouteID,$t);
	// link to show a route on the map
	$resultString.=	"<br/><br/><a href=\"code_source.php?sid=" . $CONF['SESSION_ID'] . "&src=Map24MapletRemoteControl_showRoute.php5\" target=\"codeframe\"> MRC-Command to show the route on the map</a>";
}
else
{
	$resultString= "No Answer from the Webserver";
}

?>